﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.ViewModel;
using EF41RiaServicesSample.Web.Models;
using System.Collections.ObjectModel;
using Microsoft.Practices.Prism.Commands;
using EF41RiaServicesSample.Web.Services;

namespace EF41RiaServicesSample
{
    public class MainViewModel : NotificationObject
    {
        private ObservableCollection<Driver> _Drivers;
        /// <summary>
        /// Drivers
        /// </summary>
        public ObservableCollection<Driver> Drivers
        {
            get
            {
                return _Drivers;
            }
            set
            {
                if (value == _Drivers) return;

                _Drivers = value;
                RaisePropertyChanged(() => Drivers);
            }
        }


        private DelegateCommand _GetCommand;
        /// <summary>
        /// GetCommandを取得します
        /// </summary>
        public DelegateCommand GetCommand
        {
            get
            {
                if (_GetCommand == null)
                {
                    _GetCommand = new DelegateCommand(Get);
                }
                return _GetCommand;
            }
        }

        /// <summary>
        /// GetCommandの実装メソッド
        /// </summary>
        private void Get()
        {
            var context = new SampleContext();

            //Driversを取得します。
            context.Load(
                context.GetDriversQuery(),
                loadOperation => 
                {
                    Drivers = new ObservableCollection<Driver>(loadOperation.Entities);
                },
                null);
        }

    }
}
